//
//  MJGIFFooter.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/21.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "MJGIFFooter.h"

@implementation MJGIFFooter


- (void)prepare
{
    [super prepare];
    self.mj_h = 80;
    // 添加label
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont boldSystemFontOfSize:font12ScreenWRate * LKScreenW];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor lightGrayColor];
    [self addSubview:label];
    self.label = label;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        // 设置普通状态的动画图片
        NSMutableArray *idleImages = [NSMutableArray array];
        for (NSUInteger i = 0; i<=12; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"camp%zd", i]];
            [idleImages addObject:image];
        }
        [self setImages:idleImages forState:MJRefreshStateIdle];
        
        // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
        NSMutableArray *refreshingImages = [NSMutableArray array];
        for (NSUInteger i = 0; i<=12; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"camp%zd", i]];
            [refreshingImages addObject:image];
        }
        [self setImages:refreshingImages forState:MJRefreshStatePulling];
        
        // 设置正在刷新状态的动画图片
        
        NSMutableArray *StateRefreshingImages = [NSMutableArray array];
        for (NSUInteger i = 0; i<=12; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"camp%zd", i]];
            [refreshingImages addObject:image];
        }
        
        [self setImages:StateRefreshingImages forState:MJRefreshStateRefreshing];
        
    });

}

/*
 
 self.tableView.mj_header = [MJGIFHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
 
 self.tableView.mj_footer = [MJGIFFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
 
 */
#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews
{
    [super placeSubviews];
    self.gifView.contentMode = UIViewContentModeScaleToFill;
    self.gifView.frame = CGRectMake(self.width * 0.5 - 30, 0, 70, 55);
    self.label.frame = CGRectMake(self.width * 0.5 - 50, CGRectGetMaxY(self.gifView.frame), 100, 25);
    self.label.centerX = self.gifView.centerX;
}

#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
    [super scrollViewContentOffsetDidChange:change];
    
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
    
}

#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
    [super scrollViewPanStateDidChange:change];
    
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
            self.label.text = @"上拉加载更多";
            break;
        case MJRefreshStateRefreshing:
            self.label.text = @"加载中...";
            break;
        case MJRefreshStateNoMoreData:
            self.label.text = @"木有数据啦";
            break;
        default:
            break;
    }
}



@end
